# Huawei Technologies Co.,Ltd.

set(MODULE_OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/module.txt)
set(MODULE_JS_A ${CMAKE_CURRENT_SOURCE_DIR}/module_a.js)
set(MODULE_JS_B ${CMAKE_CURRENT_SOURCE_DIR}/module_b.js)
set(MODULE_JS_C ${CMAKE_CURRENT_SOURCE_DIR}/module_c.js)
set(MODULE_BIN_A ${CMAKE_CURRENT_BINARY_DIR}/module_a.abc)
set(MODULE_BIN_B ${CMAKE_CURRENT_BINARY_DIR}/module_b.abc)
set(MODULE_BIN_C ${CMAKE_CURRENT_BINARY_DIR}/module_c.abc)
set(MODULE_VERIFY ${CMAKE_CURRENT_SOURCE_DIR}/verify.sh)

set(RUNTIME_ARGUMENTS --boot-panda-files=${PANDA_BINARY_ROOT}/pandastdlib/arkstdlib.abc --load-runtimes=\"ecmascript\" --compiler-enable-jit=false ${MODULE_BIN_A} _GLOBAL::func_main_0)

add_custom_command(
    OUTPUT ${MODULE_OUTPUT}
    COMMENT "running javascript module testcase"
    COMMAND ${PANDA_RUN_PREFIX} $<TARGET_FILE:es2panda> --module ${MODULE_JS_A} --output ${MODULE_BIN_A}
    COMMAND ${PANDA_RUN_PREFIX} $<TARGET_FILE:es2panda> --module ${MODULE_JS_B} --output ${MODULE_BIN_B}
    COMMAND ${PANDA_RUN_PREFIX} $<TARGET_FILE:es2panda> --module ${MODULE_JS_C} --output ${MODULE_BIN_C}
    COMMAND rm -f ${MODULE_OUTPUT}
    COMMAND ${PANDA_RUN_PREFIX} $<TARGET_FILE:ark> ${RUNTIME_ARGUMENTS} 2>&1 > ${MODULE_OUTPUT}
    COMMAND bash ${MODULE_VERIFY} ${MODULE_OUTPUT}
)
add_custom_target(module
    DEPENDS ${MODULE_OUTPUT} ${MODULE_VERIFY}
)
add_dependencies(module ark_asm ark)
add_dependencies(ecmascript_common_tests module)
